package dbms.symbol;

import java.util.*;

class Item {
	Object value;
	Symbol sym;
	Item next;
	
	public Item (Object v, Symbol s, Item i) {
		value = v;
		sym = s;
		next = i;
	}
}

public class Table {
	
	private HashMap<Symbol, Item> dict = new HashMap<Symbol, Item>();
	private Symbol top;
	private Item item;
	
	public Object get(Symbol s) {
		Item item = (Item) dict.get(s);
		if (item == null) return null;
		else return item.value;
	}
	
	public void put(Symbol s, Object value) {
		dict.put(s, new Item(value, top, (Item) dict.get(s)));
		top = s;
	}
	
	public void BeginScope () {
		item = new Item(null, top, item);
		top = null;
	}
	
	public void EndScope () {
		while (top != null) {
			Item i = (Item)dict.get(top);
			if (i.next != null) dict.put(top,i.next);
			else dict.remove(top);
			top = i.sym;
		}
		top=item.sym;
		item=item.next;
	}
}